//
// Created by dave on 18-7-29.
//

#pragma once

#include <string>
#include "../msg_body.h"
#include "../data_utils.h"

class TermRegister : public MsgBody {
public:
    void decode(std::vector<char> data, std::size_t start, std::size_t stop) override {
        province_ = read_word(data, start);
        city_ = read_word(data, start + 2);
        maker_ = std::string(&data[start + 4], 5);
        model_ = std::string(&data[start + 9], 8);
        deviceId_ = std::string(&data[start + 17], 7);
        color_ = data[start + 24];
        license_ = gbk2utf8(std::string(&data[start + 25], (stop - start - 25)));
    }

    std::vector<char> encode() override {
        std::vector<char> vec;
        write_word(vec, province_);
        write_word(vec, city_);
        write_bytes(vec, maker_.c_str(), 5);
        write_bytes(vec, model_.c_str(), 8);
        write_bytes(vec, deviceId_.c_str(), 7);
        vec.push_back(color_);
        std::string gbk = utf8_gbk(license_);
        write_bytes(vec, gbk.c_str(), gbk.size());
        return vec;
    }

    short getProvince() const { return province_; }
    void setProvince(short province) { this->province_ = province; }

    short getCity() const { return city_; }
    void setCity(short city) { this->city_ = city; }

    std::string getMaker() const { return maker_; }
    void setMaker(std::string maker) { this->maker_ = maker; }

    std::string getModel() const { return model_; }
    void setModel(std::string model) { this->model_ = model; }

    std::string getDeviceId() const { return deviceId_; }
    void setDeviceId(std::string deviceId) { this->deviceId_ = deviceId; }

    char getColor() const { return color_; }
    void setColor(char color) { this->color_ = color; }

    std::string getLicense() const { return license_; }
    void setLicense(std::string license) { this->license_ = license; }

private:
    /// 省域 ID（参考  GB/T 2260 中规定的行政区划代码六位中前两位）
    short province_;
    /// 市县域 ID（参考  GB/T 2260 中规定的行政区划代码六位中后四位）
    short city_;
    /// 制造商 ID
    std::string maker_;
    /// 终端型号
    std::string model_;
    /// 终端 ID
    std::string deviceId_;
    /// 车牌颜色（参考 JT/T415-2006 的 5.4.12） 0-未上牌, 1-蓝色, 2-黄色, 3-黑色, 4-白色
    char color_;
    /// 车牌
    std::string license_;
};